﻿#!/usr/bin/env python3

from functools import *

def myadd(a, b):
    return a+b

def decorator1(f):
    @wraps(f)
    def wrapper():
        return f()
    return wrapper

@decorator1
def func1():
    return "hello"
    
def decorator2(f):
    def wrapper():
        return f()
    return wrapper

@decorator2
def func2():
    return "hello"


def main():
    '''
functools -  用于function的工具
@lru_cache
partial(), 对callable obj的封装,使得已知的入参得以固定, 返回的callable被调用时,只需指定待定入参即可
partialmethod()
update_wrapper(), 修改wrapper func使得其看起来像wrapped func. wrapper中添加一个__wrapped__属性表明其wrapper的情况.
@wraps, 效果等同于update_wrapper

    '''
    print(main.__doc__)
    print("="*30)

    myadd1 = partial(myadd, a = 10)
    print(myadd1(b=5))

    myadd2 = partial(myadd, b = 10)
    print(myadd2(5))        #按pos赋值给a

    print(func1.__name__)       # func1
    print(func2.__name__)       # wrapper




    




if __name__=='__main__':
    main()


